<?php

namespace common\models\db\tables;

use Yii;

/**
 * This is the model class for table "{{%test_tt}}".
 *
 * @property string $id
 * @property string $pid
 * @property string $icon
 * @property string $icon_color
 * @property string $name
 * @property int $sort
 *
 * @property TestTt $p
 * @property TestTt[] $testTts
 */
class TestTt extends \yii\db\ActiveRecord
{
    /**
     * {@inheritdoc}
     */
    public static function tableName()
    {
        return '{{%test_tt}}';
    }

    /**
     * {@inheritdoc}
     */
    public function rules()
    {
        return [
            [['pid', 'sort'], 'integer'],
            [['name'], 'required'],
            [['icon', 'icon_color', 'name'], 'string', 'max' => 255],
            [['pid'], 'exist', 'skipOnError' => true, 'targetClass' => TestTt::className(), 'targetAttribute' => ['pid' => 'id']],
        ];
    }

    /**
     * {@inheritdoc}
     */
    public function attributeLabels()
    {
        return [
            'id' => Yii::t('app', 'ID'),
            'pid' => Yii::t('app', 'Pid'),
            'icon' => Yii::t('app', 'Icon'),
            'icon_color' => Yii::t('app', 'Icon Color'),
            'name' => Yii::t('app', 'Name'),
            'sort' => Yii::t('app', 'Sort'),
        ];
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getP()
    {
        return $this->hasOne(TestTt::className(), ['id' => 'pid']);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getTestTts()
    {
        return $this->hasMany(TestTt::className(), ['pid' => 'id']);
    }
}
